# 创建集合
# 集合特点：元素不重复
s = set()
print(s,type(s))

s = {1,2,3,4}
print(s,type(s))

s = {1,2,3,4,3,2,1,4}
print(s,type(s))

s = set([1,2,3,2])  # list -> set
print(s)

s = set((1,2,3))  # tuple -> set
print(s)

s = set("123")  # str -> set
print(s)

s = set({1:"a","a":2})  # dict -> set
print(s)

# 集合常用函数
# in
print(1 in s)
# len
print(len(s))
# max/min
print(max({1,2,3,4}))
# del

# 集合的遍历
for i in s:
    print(i)


# 集合常用方法
# 拼接集合
## 会将待拼接集合随机拼接在目标集合任意元素后面
s.update({5,6,7,8})
print(s)
# 复制集合
sp = s.copy()
print(sp)
# 移除集合内指定元素
s.remove('a')
print(s)

# 集合的交集
s2 = {5,6,7,8,9}
print(s & s2)
# 集合的并集
print( s| s2)

# 1.列表去重
score = [80,70,60,80,70,60,40]
s = set(score)
print(s)

# 2.统计各个分数的学生数
for i in s:
    t = score.count((i))
    print(f"得分为{i}的学生有{t}个")



